home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / slib / elk.init < prev    next >
Encoding:
Text File  |  1995-01-04  |  8.3 KB  |  282 lines

  1. ;;;"elk.init" Initialisation file for SLIB for ELK 2.1    -*- Scheme -*-
  2. ;;; Copyright (C) 1991, 1992, 1993 Aubrey Jaffer.
  3. ;
  4. ;Permission to copy this software, to redistribute it, and to use it
  5. ;for any purpose is granted, subject to the following restrictions and
  6. ;understandings.
  7. ;
  8. ;1.  Any copy made of this software must include this copyright notice
  9. ;in full.
  10. ;
  11. ;2.  I have made no warrantee or representation that the operation of
  12. ;this software will be error-free, and I am under no obligation to
  13. ;provide any services, by way of maintenance, update, or otherwise.
  14. ;
  15. ;3.  In conjunction with products arising from the use of this
  16. ;material, there shall be no use of my name in any advertising,
  17. ;promotional, or sales literature without prior written consent in
  18. ;each case.
  19.  
  20. ; No guarantees are given about the correctness of any of the
  21. ; choices made below.  Only enough work was done to get the require
  22. ; mechanism to work correctly.
  23. ;
  24. ; Stephen J. Bevan <bevan@cs.man.ac.uk> 19920912 modified by Mike
  25. ; Sperber to work correctly with statically-linked Elk and slib1d.  Be
  26. ; sure to change the library vicinities according to your local
  27. ; configuration.  If you're running MS-DOS (which is possible since
  28. ; 2.1), you probably have to change this file to make everything work
  29. ; correctly.
  30.  
  31. ;;; (software-type) should be set to the generic operating system type.
  32. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported.
  33.  
  34. (define (software-type) 'UNIX)
  35.  
  36. ;;; (scheme-implementation-type) should return the name of the scheme
  37. ;;; implementation loading this file.
  38.  
  39. (define (scheme-implementation-type) 'Elk)
  40.  
  41. ;;; (scheme-implementation-version) should return a string describing
  42. ;;; the version the scheme implementation loading this file.
  43.  
  44. (define (scheme-implementation-version) "?2.1")
  45.  
  46. ;;; (implementation-vicinity) should be defined to be the pathname of
  47. ;;; the directory where any auxillary files to your Scheme
  48. ;;; implementation reside.
  49.  
  50. (define (implementation-vicinity)
  51.   (case (software-type)
  52.     ((UNIX)     "/usr/local/lib/elk-2.1/scm/")
  53.     ((VMS)    "scheme$src:")
  54.     ((MS-DOS)    "C:\\scheme\\")))
  55.  
  56. ;;; (library-vicinity) should be defined to be the pathname of the
  57. ;;; directory where files of Scheme library functions reside.
  58.  
  59. (define library-vicinity
  60.   (let ((library-path
  61.      (or (getenv "SCHEME_LIBRARY_PATH")
  62.          ;; Uses this path if SCHEME_LIBRARY_PATH is not defined.
  63.          (case (software-type)
  64.            ((UNIX) "/usr/local/lib/slib/")
  65.            ((VMS) "lib$scheme:")
  66.            ((MS-DOS) "C:\\SLIB\\")
  67.            (else "")))))
  68.     (lambda () library-path)))
  69.  
  70. ;;; *features* should be set to a list of symbols describing features
  71. ;;; of this implementation.  Suggestions for features are:
  72.  
  73. (define *features*
  74.       '(
  75.     source                ;can load scheme source files
  76.                     ;(slib:load-source "filename")
  77.     compiled            ;can load compiled files
  78.                     ;(slib:load-compiled "filename")
  79.     rev4-report
  80.     ieee-p1178
  81.     sicp
  82.     rev4-optional-procedures
  83.     rev3-procedures
  84.     rev2-procedures
  85.     multiarg/and-
  86.     multiarg-apply
  87.     delay
  88.     transcript
  89.     full-continuation
  90.     sort
  91.     format
  92.     system
  93.     getenv
  94.     program-arguments
  95.     string-port
  96.     ))
  97.  
  98. ;------------
  99.  
  100. (define program-arguments
  101.   (lambda ()
  102.     (cons "undefined-program-name" (command-line-args))))
  103.  
  104. ; EXACT? appears to always return #f which isn't very useful.
  105. ; Approximating it with INTEGER? at least means that some
  106. ; of the code in the library will work correctly
  107.  
  108. (define exact? integer?)  ; WARNING: redefining EXACT?
  109.  
  110. (define (inexact? arg)
  111.   (not (exact? arg)))
  112.  
  113. ;;; (TMPNAM) makes a temporary file name.
  114. (define tmpnam
  115.   (let ((cntr 100))
  116.     (lambda () (set! cntr (+ 1 cntr))
  117.         (let ((tmp (string-append "slib_" (number->string cntr))))
  118.           (if (file-exists? tmp) (tmpnam) tmp)))))
  119.  
  120. (require 'unix)
  121.  
  122. ; Pull in GENTENV and SYSTEM
  123.  
  124. ;;; (FILE-EXISTS? <string>) already here.
  125.  
  126. ;;; (DELETE-FILE <string>)
  127. (define (delete-file f) (system (string-append "rm " f)))
  128.  
  129. ;------------
  130.  
  131. ;;; (OUTPUT-PORT-WIDTH <port>)
  132. (define (output-port-width . arg) 79)
  133.  
  134. ;;; (OUTPUT-PORT-HEIGHT <port>)
  135. (define (output-port-height . arg) 24)
  136.  
  137. ;;; (CURRENT-ERROR-PORT)
  138. ;;; is already defined in Elk 2.1
  139.  
  140. ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
  141. ;;; use this definition if your system doesn't have such a procedure.
  142. (define force-output flush-output-port)
  143.  
  144. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  145. ;;; port versions of CALL-WITH-*PUT-FILE.
  146. (define (call-with-output-string f)
  147.   (let ((outsp (open-output-string)))
  148.     (f outsp)
  149.     (let ((s (get-output-string outsp)))
  150.       (close-output-port outsp)
  151.       s)))
  152.  
  153. (define (call-with-input-string s f)
  154.   (let* ((insp (open-input-string s))
  155.      (res (f insp)))
  156.     (close-input-port insp)
  157.     res))
  158.  
  159. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  160. ;;; be returned by CHAR->INTEGER.
  161. (define char-code-limit 256)
  162.  
  163. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  164. (define most-positive-fixnum 8388608)  ; 23 bit integers ?
  165.  
  166. ;;; Return argument
  167. (define (identity x) x)
  168.  
  169. ;;; If your implementation provides eval SLIB:EVAL is single argument
  170. ;;; eval using the top-level (user) environment.
  171. (define slib:eval eval)
  172.  
  173. (define *macros* '())
  174. (define (defmacro? m) (and (assq m *macros*) #t))
  175.  
  176. (define-macro (defmacro key pattern . body)
  177.   `(begin
  178.      (define-macro ,(cons key pattern) ,@body)
  179.      (set! *macros* (cons (cons ',key (lambda ,pattern ,@body)) *macros*))))
  180.  
  181. (define (macroexpand-1 e)
  182.   (if (pair? e) (let ((a (car e)))
  183.           (cond ((symbol? a) (set! a (assq a *macros*))
  184.                      (if a (apply (cdr a) (cdr e)) e))
  185.             (else e)))
  186.       e))
  187.  
  188. (define (macroexpand e)
  189.   (if (pair? e) (let ((a (car e)))
  190.           (cond ((symbol? a)
  191.              (set! a (assq a *macros*))
  192.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  193.             (else e)))
  194.       e))
  195.  
  196. (define gentemp
  197.   (let ((*gensym-counter* -1))
  198.     (lambda ()
  199.       (set! *gensym-counter* (+ *gensym-counter* 1))
  200.       (string->symbol
  201.        (string-append "slib:G" (number->string *gensym-counter*))))))
  202.  
  203. (define defmacro:eval slib:eval)
  204. (define defmacro:load load)
  205. ;;; If your implementation provides R4RS macros:
  206. ;(define macro:eval slib:eval)
  207. ;(define macro:load load)
  208.  
  209. (define (slib:eval-load <pathname> evl)
  210.   (if (not (file-exists? <pathname>))
  211.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  212.   (call-with-input-file <pathname>
  213.     (lambda (port)
  214.       (let ((old-load-pathname *load-pathname*))
  215.     (set! *load-pathname* <pathname>)
  216.     (do ((o (read port) (read port)))
  217.         ((eof-object? o))
  218.       (evl o))
  219.     (set! *load-pathname* old-load-pathname)))))
  220.  
  221. ;;; define an error procedure for the library
  222. (define slib:error error)
  223.  
  224. ;;; define these as appropriate for your system.
  225. (define slib:tab #\tab)
  226. (define slib:form-feed #\formfeed)
  227.  
  228. ;;; Define these if your implementation's syntax can support it and if
  229. ;;; they are not already defined.
  230.  
  231. ;(define (1+ n) (+ n 1))
  232. ;(define (-1+ n) (+ n -1))
  233. ;(define 1- -1+)
  234.  
  235. (define in-vicinity string-append)
  236.  
  237. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  238. ;;; return if exitting not supported.
  239. (define slib:exit
  240.   (lambda args
  241.     (exit (cond ((null? args) 0)
  242.         ((eqv? #t (car args)) 0)
  243.         ((and (number? (car args)) (integer? (car args))) (car args))
  244.         (else 1)))))
  245.  
  246. ;;; Here for backward compatability
  247. (define scheme-file-suffix
  248.   (let ((suffix (case (software-type)
  249.           ((NOSVE) "_scm")
  250.           (else ".scm"))))
  251.     (lambda () suffix)))
  252.  
  253. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  254. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  255.  
  256. ; Modify the already modified _load_ so that it copes with
  257. ; environments correctly.  The change involves using
  258. ; _(global-environment)_ if none is explicitly specified.
  259. ; If this is not done, definitions in files loaded by other files will
  260. ; not be loaded in the correct environment.
  261.  
  262. (define slib:load-source
  263.   (let ((primitive-load load))
  264.     (lambda (<pathname> . rest)
  265.       (let ((env (if (null? rest) (list (global-environment)) rest)))
  266.     (apply primitive-load <pathname> env)))))
  267.  
  268. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  269. ;;; by compiling "foo.scm" if this implementation can compile files.
  270. ;;; See feature 'COMPILED.
  271.  
  272. (define slib:load-compiled
  273.   (let ((primitive-load load))
  274.     (lambda (<pathname> . rest)
  275.       (apply primitive-load (string->symbol (string-append name ".o")) rest))))
  276.  
  277. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  278.  
  279. (define slib:load slib:load-source)    ;WARNING: redefining LOAD
  280.  
  281. (slib:load (in-vicinity (library-vicinity) "require"))
  282.